package com.example.usercenter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * RedisConfig配置
 * @author 米饭好好吃
 */
@Configuration
public class RedisConfig {
    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory connectionFactory) {
        // 1. 创建RedisTemplate
        RedisTemplate redisTemplate = new RedisTemplate();
        // 2. 设置连接工厂
        redisTemplate.setConnectionFactory(connectionFactory);
        // 3. 重写序列化器
        redisTemplate.setKeySerializer(RedisSerializer.string());
        return redisTemplate;
    }
}
